<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input v-model="keyword" type="text" placeholder="请输入内容"/>&nbsp;
      <button @click="search">Search</button>
    </div>
  </section>
</template>

<script>
import axios from 'axios'
export default {
  name: "Search",
  data() {
    return {
      keyword: ""
    }
  },
  methods:{
    search(){
      //获取用户输入
    const {keyword}=this
      //发送请求前通过$bus传给List
      this.$bus.$emit('personData',{users:[],isFirst:false,isLoading:true,errMsg:''})
      //发送请求
      axios.get('https://api.github.com/search/users',{params:{q:keyword}}).then(
          response=>{
            console.log(response.data.items)//请求数据成功
            const {items}=response.data
            //请求成功 通过$bus传给List
            this.$bus.$emit('personData', {users:items,isFirst:false,isLoading:false,errMsg:''})
          },
          error=>{
            console.log(error.message)
            //请求成功 通过$bus传给List
            this.$bus.$emit('personData', {users:[],isFirst:false,isLoading:false,errMsg:error.message})
          }
      )
    }
  }
}
</script>

<style scoped>

</style>